package com.atu.poker.dao.impl;

import java.util.List;

import com.atu.poker.dao.DAO;
import com.atu.poker.dao.RoomInfoDAO;
import com.atu.poker.po.RoomInfo;

public class RoomInfoDAOJdbcImpl extends DAO<RoomInfo> implements RoomInfoDAO{

	@Override
	public void createRoom(RoomInfo roomInfo){
		String sql = "INSERT INTO t_room(room_id,room_name,create_user,create_time,upper_chip,lower_chip,user_limit,room_status) VALUES(?,?,?,?,?,?,?,?)";
		update(sql, roomInfo.getRoomId(), roomInfo.getRoomName(), roomInfo.getCreateUser(), roomInfo.getCreateTime(),
				roomInfo.getUpperChip(), roomInfo.getLowerChip(), roomInfo.getUserLimit(), roomInfo.getRoomStatus());
	}

	@Override
	public List<RoomInfo>  getNotCloseRoomList(String filterRoom) {
		String sql = "SELECT room_id roomId,room_name roomName,create_user createUser,create_time createTime,upper_chip upperChip,lower_chip lowerChip,user_limit userLimit,room_status roomStatus FROM t_room WHERE room_status!='0' AND room_name like ? ORDER BY create_time DESC";
		return getForList(sql,"%"+filterRoom+"%");
	}

	@Override
	public void changeRoomStatus(String searId,String roomStatus){
		String sql = "UPDATE t_room r SET r.room_status=? WHERE r.room_status!='0' AND r.create_user=(SELECT s.user_id FROM t_seat s WHERE seat_id=?)";
		update(sql, roomStatus,searId);
	}

	@Override
	public RoomInfo getNotCloseRoom(String userId){
		String sql = "SELECT room_id roomId,room_name roomName,create_user createUser,create_time createTime,upper_chip upperChip,lower_chip lowerChip,user_limit userLimit,room_status roomStatus FROM t_room WHERE room_status!='0' AND create_user=?";
		return get(sql, userId);
	}

	@Override
	public String getNotCloseRoomStatus(String userId) {
		String sql = "SELECT room_status FROM t_room WHERE room_status!='0' AND create_user=?";
		return getForValue(sql, userId);
	}

	@Override
	public String getUserLimit(String roomId) {
		String sql = "SELECT user_limit FROM t_room WHERE room_id=?";
		return getForValue(sql, roomId);
	}

}
